<template>
  <div class="ma-content-block">
    <sa-table ref="crudRef" :options="options" :columns="columns" :searchForm="searchForm">
	<template #wechatUser="{ record }">
  <span class="arco-auto-tooltip arco-table-td-content">
    <span class="arco-auto-tooltip-content">
      <!-- 新增一个容器用于图片和商品名称并排显示 -->
      <div class="image-name-container" style="display: flex; align-items: center;">
        <img  
          class="time-info goods-image"  
          data-v-49576cc5="" 
          :src="record.wechatUser.avatar" 
          style="object-fit: cover; cursor: pointer; width: 80px; height: 80px; border-radius: 50%; margin-right: 10px;"
        >
        <span class="time-info goods-name">{{record.wechatUser.nickname}}</span>
      </div>
    </span>
  </span>
</template>
      <!-- 搜索区 tableSearch -->
      <template #tableSearch>
        <a-col :span="8">
          <a-form-item label="日志类型" field="type">
            <sa-select v-model="searchForm.type" dict="LogType" placeholder="请选择日志类型" allow-clear />
          </a-form-item>
        </a-col>
		<a-col :span="8">
		  <a-form-item label="用户昵称" field="nickname">
		    <a-input v-model="searchForm.nickname" placeholder="请输入用户昵称" />
		  </a-form-item>
		</a-col>
		<a-col :span="8">
		  <a-form-item label="手机号" field="phone">
		    <a-input v-model="searchForm.phone" placeholder="请输入手机号" />
		  </a-form-item>
		</a-col>
      </template>

      <!-- Table 自定义渲染 -->
    </sa-table>

    <!-- 编辑表单 -->
    <edit-form ref="editRef" @success="refresh" />
  </div>
</template>

<script setup>
import { onMounted, ref, reactive } from 'vue'
import { Message } from '@arco-design/web-vue'
import EditForm from './edit.vue'
import api from '../api/logs'
import { useRoute } from 'vue-router'
// 引用定义
const crudRef = ref()
const editRef = ref()
const route = useRoute()
// 搜索表单
const searchForm = ref({
  type: '',
  nickname:'',
  phone:'',
  user_id: route.query.user_id || ''

})


// SaTable 基础配置
const options = reactive({
  api: api.getPageList,
  pk: 'log_id',
  // recycleApi: api.getRecyclePageList,
  rowSelection: { showCheckedAll: true },
  operationColumn:false,
  add: {
    show: false,
    auth: ['/EbProductLogs/EbProductLogs/save'],
    func: async () => {
      editRef.value?.open()
    },
  },
  edit: {
    show: false,
    auth: ['/EbProductLogs/EbProductLogs/update'],
    func: async (record) => {
      editRef.value?.open('edit')
      editRef.value?.setFormData(record)
    },
  },
  delete: {
    show: false,
    auth: ['/EbProductLogs/EbProductLogs/destroy'],
    func: async (params) => {
      const resp = await api.delete(params)
      if (resp.code === 200) {
        Message.success(`删除成功！`)
        crudRef.value?.refresh()
      }
    },
    realAuth: ['/EbProductLogs/EbProductLogs/realDestroy'],
    realFunc: async (params) => {
      const resp = await api.realDestroy(params)
      if (resp.code === 200) {
        Message.success(`销毁成功！`)
        crudRef.value?.refresh()
      }
    },
  },
  recovery: {
    show: false,
    auth: ['/EbProductLogs/EbProductLogs/recovery'],
    func: async (params) => {
      const resp = await api.recovery(params)
      if (resp.code === 200) {
        Message.success(`恢复成功！`)
        crudRef.value?.refresh()
      }
    },
  },
   export: { show: true, url: '/EbProductLogs/EbProductLogs/export', auth: ['/EbProductLogs/EbProductLogs/export'] },
})

// SaTable 列配置
const columns = reactive([
  { title: '用户信息', dataIndex: 'wechatUser', width: 120 },
  { title: '手机号', dataIndex: 'wechatUser.phone', width: 180 },			 
  { title: '日志类型', dataIndex: 'type', dict: 'LogType', width: 120 },
  { title: '日志内容', dataIndex: 'remark', width: 180 },
  { title: '日志时间', dataIndex: 'create_time', width: 180 }
])

// 页面数据初始化
const initPage = async () => {}

// SaTable 数据请求
const refresh = async () => {
  crudRef.value?.refresh()
}

// 页面加载完成执行
onMounted(async () => {
  initPage()
  refresh()
})
</script>
